package zhanglinwei.cryptotools.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import zhanglinwei.cryptotools.core.processor.EnableCryptoPropertyBeanFactoryPostProcessor;
import zhanglinwei.cryptotools.core.resolver.CryptoablePropertyResolver;
import zhanglinwei.cryptotools.core.resolver.CryptoablePropertyResolverFactory;
import zhanglinwei.cryptotools.core.resolver.impl.AESResolver;
import zhanglinwei.cryptotools.core.resolver.impl.SM4CBCResolver;
import zhanglinwei.cryptotools.core.resolver.impl.SM4ECBResolver;

@Configuration
@EnableConfigurationProperties(value = {CryptoToolsProperties.class})
@ConditionalOnProperty(
        name = "crypto-tools.enable",
        havingValue = "true",
        matchIfMissing = true
)
public class CryptoToolsAutoConfiguration {

    @Bean
    public static EnableCryptoPropertyBeanFactoryPostProcessor enableCryptoPropertyBeanFactoryPostProcessor() {
        return new EnableCryptoPropertyBeanFactoryPostProcessor();
    }

    @Bean
    public CryptoablePropertyResolverFactory cryptoablePropertyResolverFactory(ApplicationContext applicationContext) {
        return new CryptoablePropertyResolverFactory(applicationContext);
    }

    @Bean
    public CryptoablePropertyResolver aesResolver() {
        return new AESResolver();
    }

    @Bean
    public CryptoablePropertyResolver sm4CBCResolver() {
        return new SM4CBCResolver();
    }

    @Bean
    public CryptoablePropertyResolver sm4ECBResolver() {
        return new SM4ECBResolver();
    }

}
